# --**coding:utf-8**--
from django.shortcuts import render
from django.http import JsonResponse, HttpResponse
from django.views.decorators.http import require_http_methods
from django.shortcuts import render_to_response
import json,time,urllib
import returnInfo


# Create your views here.

def index(request,params):
    # test
    print 'parms:',params
    return HttpResponse('test')


@require_http_methods(["GET", "POST"])
def nanjingZS(request,parms):
    '''
    :param request: 当前get，未对入参做校验
    :return:南京甄视写死json串
    '''
    if request.method == "GET":
        returnMessage = returnInfo.nanjingZs()
        return JsonResponse(returnMessage)
    else:
        if int(str(parms)) == 500:
            time.sleep(0.5)
            returnMessage = returnInfo.nanjingZs()
            return JsonResponse(returnMessage)
        elif int(str(parms)) == 1000:
            time.sleep(1)
            returnMessage = returnInfo.nanjingZs()
            return JsonResponse(returnMessage)
        elif int(str(parms)) ==1500:
            time.sleep(1.5)
            returnMessage = returnInfo.nanjingZs()
            return JsonResponse(returnMessage)
        elif int(str(parms)) ==2000:
            time.sleep(2)
            returnMessage = returnInfo.nanjingZs()
            return JsonResponse(returnMessage)
        elif int(str(parms)) ==869:
            time.sleep(0.869)
            returnMessage = returnInfo.nanjingZs()
            return JsonResponse(returnMessage)
        returnMessage = returnInfo.nanjingZs()
        return JsonResponse(returnMessage)
def bankCard(request):
    '''
    :param request: 当前get，未对入参做校验
    :return: ocr/bankcard  改成了json串
    '''
    time.sleep(0.853)
    bankCardInfo = returnInfo.OCRBankCard()
    return JsonResponse(bankCardInfo)


def jiupaiFourElements(request,parms):
    '''
    :param request: 四要素和二要素需要对入参左校验，authIdCheck：二要素；bankAuthCheck：四要素
    :return: 九派四要素，直接return字符串
    '''
    if int(str(parms)) == 500:
        time.sleep(0.5)
        return JsonResponse(returnInfo.songshun())
    elif int(str(parms)) == 1000:
        time.sleep(1)
        return JsonResponse(returnInfo.songshun())
    elif int(str(parms)) == 200:
        time.sleep(0.2)
        return JsonResponse(returnInfo.songshun())
    elif int(str(parms)) == 816:
        time.sleep(0.816)
        return JsonResponse(returnInfo.songshun())
    # if request.POST.get('service') == 'authIdCheck':
    #     # print request.POST.get('service')
    #     return HttpResponse(returnInfo.songshun())
    # elif request.POST.get('service') == 'bankAuthCheck':
    #     # print request.POST.get('service')
    #     return JsonResponse(returnInfo.songshun())


def jiupaiTwoElements(request,parms):
    '''
    :param request: 二要素等待500ms
    :return: 九派二要素，直接return字符串
    '''
    if int(str(parms)) == 500:
        time.sleep(0.5)
        return JsonResponse(returnInfo.guangdian())
    elif int(str(parms)) == 200:
        time.sleep(0.2)
        return JsonResponse(returnInfo.guangdian())
    elif int(str(parms)) == 217:
        time.sleep(0.217)
        return JsonResponse(returnInfo.guangdian())

def getPortrait(request):
    # 九派底图
    return JsonResponse(returnInfo.getJiupaiBaseMap())
def saveUnmatchPortrait(request):
    # 保存不匹配图
    return JsonResponse(returnInfo.saveUnmatchPortrait())

def saveOcrPortrait(request):
    # 保存ocr图
    return JsonResponse(returnInfo.saveOcrPortrait())

def identityTwoElements(request):
    '''
    人证
    :param : 无
    :return:
    '''
    return HttpResponse(returnInfo.identityTwoElements)


def idCard(request):
    '''
    idcard
    '''
    time.sleep(0.518)
    return JsonResponse(returnInfo.idcard())


def testPost(request):
    return JsonResponse({'key': 'velue'})


def returnxml(request):
    path = '/Users/linkface_user/PycharmProjects/mockChannel/returnxml.xml'
    mimetype = "application/xml"
    return render_to_response('querylog/../templates/linkfacemock/returnxml.xml', content_type=mimetype)



